package com.zsyg.sys.web;

import com.zsyg.common.util.JsonResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import com.zsyg.sys.service.SysRoleService;
import com.zsyg.sys.entity.SysRole;

import org.springframework.web.bind.annotation.RestController;
import com.zsyg.common.base.BaseController;

import java.util.Arrays;

/**
 * 角色表 前端控制器
 *
 * @author YangWanLi
 * @since 2018-08-16
 */
@RestController
@RequestMapping("/sys/sysRole")
public class SysRoleController extends BaseController {

    @Autowired
    private SysRoleService sysRoleService;


    /**
     * 分页
     * @param page
     * @param sysRole
     * @return
     */
    @RequestMapping(value = "/findPage",method = RequestMethod.GET)
    public JsonResultUtil findPage(Page<SysRole> page, SysRole sysRole){
        return new JsonResultUtil(sysRoleService.findPage(page,sysRole));
    }

    /**
     * 条件查询
     * @param sysRole
     * @return
     */
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public JsonResultUtil findAll(SysRole sysRole){
        return new JsonResultUtil(sysRoleService.findAll(sysRole));
    }

    /**
     * 获取
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public JsonResultUtil get(@PathVariable("id") Integer id){
        return new JsonResultUtil(sysRoleService.get(id));
    }

    /**
     * 添加
     * @param sysRole
     * @return
     */
    @RequestMapping(value = "",method = RequestMethod.POST)
    public JsonResultUtil insert(SysRole sysRole){
        return new JsonResultUtil(sysRoleService.insert(sysRole));
    }

    /**
     * 修改
     * @param sysRole
     * @return
     */
    @RequestMapping(value = "",method = RequestMethod.PUT)
    public JsonResultUtil update(SysRole sysRole){
        return new JsonResultUtil(sysRoleService.update(sysRole));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public JsonResultUtil delete(@PathVariable("id") Integer id){
        return new JsonResultUtil(sysRoleService.delete(id));
    }

    /**
     * 批量删除
     * @param ids 放在url后面
     * @return
     */
    @RequestMapping(value = "/deleteByIds",method = RequestMethod.DELETE)
    public JsonResultUtil deleteByIds(Integer [] ids){
        return new JsonResultUtil(sysRoleService.deleteByIds(Arrays.asList(ids)));
    }
}

